package de.koller.faculae.engine.planet;

import de.koller.aframe.util.math.interpolation.AInterpolation;
import java.util.Random;

public class PlanetSurface {

	public final float radius;
	
	public final float[] heights =  new float[12];
	private static final Random rnd = new Random();
	
	public PlanetSurface( float radius ) {
		this.radius = radius;
		
		for( int i = 0; i < heights.length; i++ )
			heights[i] = rnd.nextFloat() * 200f;
	}
	
	public float arrayVal( int index ) {
		int i = ( index + heights.length ) % heights.length;
		return heights[i];
	}
	
	public float heightAt( float rad ) {
		float fr = 2f*(float)Math.PI;
		float r = (rad + fr) % fr;
		
		float i = r / fr * heights.length;
		int id = (int)Math.floor( i );
		
		float h = AInterpolation.interpolate( 
				arrayVal( id-1 ),
				arrayVal( id+0 ),
				arrayVal( id+1 ),
				arrayVal( id+2 ),
				i - id );
		return radius + h;
	}
	
	
}
